/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.chart.iterfaces;

import com.bean.chart.ChartLabel;
import com.bean.chart.ChartLegend;
import com.bean.chart.editors.ChartLegendPosition;
import java.io.Serializable;
import javax.swing.JPanel;

/**
 *
 * @author Lukasz
 */
public abstract class AbstractChartComposite extends JPanel implements AbstractChartCompositeView, Serializable{

    public static final String CHART_PARAM_NAME = "chart_visible_property";
    public static final String CHARTLEGEND_PARAM_NAME = "chartLegend_visible_property";
    public static final String CHARTTITLE_PARAM_NAME = "chartTitle_visible_property";
    public static final String UNITVISIBLE_PARAM_NAME = "unit_visible_property";
    public static final String UNIT_PARAM_NAME = "unit_property";
    public static final String CHARTLEGENDPOSITION_PARAM_NAME = "chartLegend_position_property";
    
    private boolean chartLegendVisible = true;
    private boolean chartTitleVisible = true;
    private boolean chartVisible;
    private boolean unitVisible = true;
    
    private ChartLegendPosition chartLegendPosition = ChartLegendPosition.DOWN;
    private String unit = "Unit";
    
    @Override
    public void setChartVisible(boolean visible) {
        boolean oldVisible = this.chartVisible;
        this.chartVisible = visible;
        propertyChange(CHART_PARAM_NAME, oldVisible, visible);
        
    }

    @Override
    public boolean isChartVisible() {
        return chartVisible;
    }

    @Override
    public void setLegendVisible(boolean visible) {
       boolean oldVisible = this.chartLegendVisible;
       this.chartLegendVisible = visible;
       propertyChange(CHARTLEGEND_PARAM_NAME, oldVisible, visible);
    }

    @Override
    public boolean isLegendVisible() {
        return chartLegendVisible;
    }

    @Override
    public void setTitleVisible(boolean visible) {
       boolean oldVisible = this.chartTitleVisible;
       this.chartTitleVisible = visible;
       propertyChange(CHARTTITLE_PARAM_NAME, oldVisible, visible);
    }

    @Override
    public boolean isTitleVisible() {
        return chartTitleVisible;
    }

    @Override
    public void setUnitVisible(boolean visible) {
       boolean oldVisible = this.unitVisible;
       this.unitVisible = visible;
       propertyChange(UNITVISIBLE_PARAM_NAME, oldVisible, visible);
    }

    @Override
    public boolean isUnitVisible() {
        return unitVisible;
    }

    @Override
    public void setUnit(String unit) {
       String oldUnit = this.unit;
       this.unit = unit;
       propertyChange(UNIT_PARAM_NAME, oldUnit, unit);
    }

    @Override
    public String getUnit() {
        return unit;
    }
    @Override
    public void setLegendPosition(ChartLegendPosition position){
        ChartLegendPosition oldPosition = this.chartLegendPosition;
        this.chartLegendPosition = position;
        propertyChange(CHARTLEGENDPOSITION_PARAM_NAME, oldPosition, position);
    }
            
    @Override
    public ChartLegendPosition getLegendPosition(){
        return chartLegendPosition;
    }
    
    protected abstract void propertyChange(String property,boolean oldval, boolean newVal);
    protected abstract void propertyChange(String property,String oldval, String newVal);
    protected abstract void propertyChange(String property,ChartLegendPosition oldval, ChartLegendPosition newVal);
}
